import { SyncRes } from "./plugin/SyncRes";
import { BasePlugin } from "./plugin/BasePlugin";
import { Help } from "./plugin/Help";
import { Test } from "./plugin/Test";
import { ConfigUtil } from "./util/ConfigUtil";
import { UpdateLanguage } from "./plugin/UpdateLanguage";
import { SyncLanguage } from "./plugin/SyncLanguage";
import { SyncMiscInfoPhp } from "./plugin/SyncMiscInfoPhp";
import { CommitPublishClient } from "./plugin/CommitPublishClient";
import { UpdatePublishClient } from "./plugin/UpdatePublishClient";
import { UpdateGen } from "./plugin/UpdateGen";
import { PullServer } from "./plugin/PullServer";
import { UpdateDebug2Release } from "./plugin/UpdateDebug2Release";
import { PublishApk } from "./plugin/PublishApk";
import { FindEmptyDir } from "./plugin/FindEmptyDir";
import { Util } from "./util/Util";
import { ShellUtil } from "./util/ShellUtil";
import { PublishIpa } from "./plugin/PublishIpa";
import { CommitCode } from "./plugin/CommitCode";
import { UpdateCode } from "./plugin/UpdateCode";
import { PullServerManifest } from "./plugin/PullServerManifest";
import { Ne } from "./plugin/Ne";
import { CheckNe } from "./plugin/CheckNe";
import { CheckUnQuotePngByAns } from "./plugin/CheckUnQuotePngByAns";
import { SyncCfg } from "./plugin/SyncCfg";
import { UpdateServerConfig } from "./plugin/UpdateServerConfig";
import { CommitServerConfig } from "./plugin/CommitServerConfig";
import { UpdateConfig } from "./plugin/UpdateConfig";
import { BuglySymbol } from "./plugin/BuglySymbol";
import { Protoc } from "./plugin/Protoc";
import { VideoM3U8Get } from "./plugin/VideoM3U8Get";

export class Main {
    /** 插件列表 */
    static plugins: { [key: string]: BasePlugin } = {
        Test: new Test(),
        Help: new Help(),
        SyncRes: new SyncRes(),
        SyncLanguage: new SyncLanguage(),
        SyncMiscInfoPhp: new SyncMiscInfoPhp(),
        UpdateCode: new UpdateCode(),
        UpdateLanguage: new UpdateLanguage(),
        UpdatePublishClient: new UpdatePublishClient(),
        UpdateServerConfig: new UpdateServerConfig(),
        UpdateConfig: new UpdateConfig(),
        CommitCode: new CommitCode(),
        CommitPublishClient: new CommitPublishClient(),
        CommitServerConfig: new CommitServerConfig(),
        UpdateGen: new UpdateGen(),
        PullServer: new PullServer(),
        PullServerManifest: new PullServerManifest(),
        UpdateDebug2Release: new UpdateDebug2Release(),
        PublishApk: new PublishApk(),
        PublishIpa: new PublishIpa(),
        FindEmptyDir: new FindEmptyDir(),
        Ne: new Ne(),
        CheckNe: new CheckNe(),
        CheckUnQuotePngByAns: new CheckUnQuotePngByAns(),
        SyncCfg:new SyncCfg(),
        BuglySymbol:new BuglySymbol(),

        Protoc: new Protoc(),
        VideoM3U8Get: new VideoM3U8Get(),
    }
    /** 项目根路径，结尾有"/" */
    static projPath: string = "";

    /** 代码根路径，比如trunk，结尾有"/" */
    static codePath: string = "";

    /** 合图工具版本 */
    static TexturePackerVersion: "3.1.2" | "4.6.3";

    static run(args: string[]) {
        this.projPath = args[0];
        let pluginName = args[1];
        let branchName = args[2];
        this.codePath = this.projPath + "client/" + branchName;
        console.log("args", args);
        args.splice(0, 3);
        // ShellUtil.exec("TexturePacker --version", (out: string) => {
        //     if (out.indexOf("3.1.2") != -1) {
        //         this.TexturePackerVersion = "3.1.2";
        //     } else {
        //         this.TexturePackerVersion = "4.6.3";
        //     }
            // ConfigUtil.load(() => {
                if (!pluginName) {
                    pluginName = "Help";// 不执行任何插件，则显示帮助
                }
                if (!this.plugins[pluginName]) {
                    throw new Error("错误的插件名：" + pluginName + "  使用./cs.sh查看所有插件名");
                }
                Util.logTime("开始执行插件" + pluginName);
                this.plugins[pluginName].do(args, () => {
                    Util.logTime("结束执行插件" + pluginName);
                });
            // });
        // });
    }
}